package makovo.utils;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

public class MailSender {
	private final int THREADS = 10;
	private ExecutorService mExecutor;
	private static MailSender mInstance;

	public static MailSender getInstance() {
		if (mInstance == null)
			synchronized (MailSender.class) {
				if (mInstance == null)
					mInstance = new MailSender();
			}

		return mInstance;
	}

	public MailSender() {
		mExecutor = Executors.newFixedThreadPool(THREADS);
	}

	public void send() throws AddressException, IOException {
		sendAsyncMail(null);

	}

	public <T extends AsyncMail> void sendAsyncMail(T mail) throws AddressException, IOException {

		SSLGMail m = (SSLGMail) new SSLGMail().setSubject("Subject")
				.setRecipients(new InternetAddress[] { new InternetAddress("ulfrheimr@live.com.mx") })
				.setMessage("Mi mensaje de prueba");

		mExecutor.execute(m);

	}
}